package com.example.bijiabao.controller;

import com.example.bijiabao.entity.book;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.bijiabao.services.indexServices;
import com.example.bijiabao.utils.Result;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("index")
public class indexcontroller {
    @Autowired
    private indexServices indexServices ;

//    //查询所有书籍信息
//    @GetMapping("/list")
//    public Result findallbook(@PathVariable("num") Integer num) {
//        Result result = new Result();
//        PageInfo<book> pageInfo=null;
//        pageInfo= indexServices.findAllbook(num);
//        result.setCode(200);
//        result.setMessage("查询成功");
//        result.setObject(pageInfo);
//        return result;
//    }

//    //index商品按评论数排序
//    @GetMapping("/listt")
//    public Result findallbookbycomnum(@PathVariable("num") Integer num) {
//        Result result = new Result();
//        PageInfo<book> pageInfo=null;
//        pageInfo= indexServices.findAllbookbycomnum(num);
//        result.setCode(200);
//        result.setMessage("查询成功");
//        result.setObject(pageInfo);
//        return result;
   // }

    //测试
   // @Controller
    //@RequestMapping("/Admin")
   // public class AdminController {
        //@Autowired
       // AdminServic adminServic;

//        @ResponseBody
//        @RequestMapping("/index1")
//        Map<String, Object> selectimg (
//                @PathVariable("num") Integer num
//        ){
//            Map<String, Object> map = new HashMap<>(); //创建一个空的map 用于返回Integer num
//            PageInfo<book> pageInfo= indexServices.findAllbookbycomnum(num); // 接受到数据
//            //map = list.stream().collect(Collectors.toMap(USERS::getID,USERS::getPwd)); //使用stream()方法将list里面的ID Pwd 以键值对放到map
//            map.put("list" ,pageInfo);
//            System.out.println(map);
//            return map;
//        }

    //热销榜

    @GetMapping("/listhot")
    public Result findhotbook() {
        Result result = new Result();
        List<book> lists=null;
        lists = indexServices.findhotbook();
        result.setCode(200);
        result.setMessage("查询成功");
        result.setObject(lists);
        return result;
    }

    @GetMapping("/listzuobian")
    public Result findAllbookbycomnum() {
        Result result = new Result();
        List<book> lists=null;
        lists = indexServices.findAllbookbycomnum();
        result.setCode(200);
        result.setMessage("查询成功");
        result.setObject(lists);
        return result;
    }

    //首页左边带分页

    @GetMapping("/list/{num}")
    public Result findallbook(@PathVariable("num") Integer num) {
        Result result = new Result();
        PageInfo<book> pageInfo=null;
        pageInfo= indexServices.findAllbook(num);
        result.setCode(200);
        result.setMessage("查询成功");
        result.setObject(pageInfo);
        return result;
    }
    }


